const mongoose = require('mongoose');

async function checkData() {
    try {
        await mongoose.connect('mongodb://127.0.0.1:27017/QWsystem');
        console.log('✅ 连接MongoDB成功\n');
        
        // 检查所有集合
        const collections = await mongoose.connection.db.listCollections().toArray();
        console.log('📁 数据库中的所有集合:');
        collections.forEach(c => console.log(`- ${c.name}`));
        
        // 导入医生模型
        const DoctorData = require('./model/DoctorData');
        
        // 获取第一个医生的完整数据
        const firstDoctor = await DoctorData.findOne({});
        console.log('\n🔍 第一个医生的完整数据结构:');
        console.log(JSON.stringify(firstDoctor, null, 2));
        
        // 检查数据问题
        console.log('\n🚨 数据问题分析:');
        
        const doctors = await DoctorData.find({});
        doctors.forEach((doc, index) => {
            console.log(`\n医生 ${index + 1}: ${doc.Doctorname}`);
            console.log(`- 科室: "${doc.Department}" ${doc.Department === '910' ? '❌ 异常' : '✅ 正常'}`);
            console.log(`- 头像: ${doc.avatar}`);
            console.log(`- 职称: ${doc.Doctorjob}`);
            console.log(`- 状态: ${doc.status}`);
            
            if (doc.schedule) {
                const scheduleObj = doc.schedule.toObject ? doc.schedule.toObject() : doc.schedule;
                const workDays = Object.entries(scheduleObj)
                    .filter(([day, isWork]) => isWork === true && day !== '_id')
                    .map(([day]) => day);
                console.log(`- 排班: [${workDays.join(', ')}]`);
            }
        });
        
        // 检查是否有头像文件
        const fs = require('fs');
        const path = require('path');
        const staticDir = path.join(__dirname, 'static');
        
        console.log('\n📁 检查static目录中的头像文件:');
        try {
            const files = fs.readdirSync(staticDir);
            const avatarFiles = files.filter(file => file.includes('doctor-avatar'));
            console.log(`找到 ${avatarFiles.length} 个医生头像文件:`);
            avatarFiles.forEach(file => console.log(`- ${file}`));
        } catch (error) {
            console.log('❌ 无法读取static目录:', error.message);
        }
        
        mongoose.connection.close();
        console.log('\n✅ 检查完成');
        
    } catch (error) {
        console.error('❌ 检查失败:', error);
    }
}

checkData(); 